﻿namespace ICMRemoteEdu
{
    using ICMRemoteEdu.Classes;
    using ICMRemoteEdu.Forms;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.IO;
    using System.Runtime.Serialization.Formatters.Binary;
    using System.Windows.Forms;

    public class ICMCourseForm : Form
    {
        private ICMCourse _course;
        private string _courseDirectory = Helper.GetCurrentFolder();
        private string _courseFileName = string.Empty;
        private IContainer components;
        public WebBrowser ContentBrowser;
        private TreeView CourseTree;
        private Info ds = new Info();
        private ImageList imageList;
        private Info info1;
        private ToolStripButton miAddPositionUser;
        private ToolStripButton miCheckResult;
        private ToolStripButton miInfo;
        private ToolStripButton miNewCourse;
        private ToolStripButton miPrint;
        private ToolStripButton miTest;
        private ToolStripButton openCourse;
        private SplitContainer splitContainer1;
        private ToolStrip toolStrip;
        private ToolStripButton toolStripButton1;
        private ToolStripButton toolStripButton2;
        private ToolStripSeparator toolStripSeparator1;
        private ToolStripSeparator toolStripSeparator2;
        private ToolStripSeparator toolStripSeparator3;
        private ToolStripSeparator toolStripSeparator4;

        public ICMCourseForm(bool adminMode)
        {
            this.InitializeComponent();
            //if (adminMode)
            //{
                //this.miNewCourse.Visible = true;
                this.miCheckResult.Visible = true;
            //}
        }

        private void CheckResultTest()
        {
            using (OpenFileDialog dialog = new OpenFileDialog())
            {
                dialog.ShowDialog();
            }
        }

        private void CourseTree_AfterSelect(object sender, TreeViewEventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;
                switch (this.CourseTree.SelectedNode.Level)
                {
                    case 0:
                    {
                        string path = this.CourseDirectory + @"\index.htm";
                        if (File.Exists(path))
                        {
                            this.ContentBrowser.Navigate(path);
                        }
                        return;
                    }
                    case 1:
                    {
                        ICMPartition partition = new ICMPartition();
                        partition.HashCode = this.CourseTree.SelectedNode.Name;
                        foreach (ICMPartition partition2 in this._course.Partitions)
                        {
                            if (ICMPartition.GetByHash(partition2, this.CourseTree.SelectedNode.Name))
                            {
                                string fullURL = partition2.GetFullURL();
                                if (File.Exists(fullURL))
                                {
                                    this.ContentBrowser.Navigate(fullURL);
                                }
                                break;
                            }
                        }
                        return;
                    }
                    case 2:
                        break;

                    default:
                        return;
                }
                ICMLesson lesson = new ICMLesson();
                lesson.HashCode = this.CourseTree.SelectedNode.Name;
                foreach (ICMPartition partition3 in this._course.Partitions)
                {
                    foreach (ICMLesson lesson2 in partition3.Lessons)
                    {
                        if (ICMLesson.GetByHash(lesson2, this.CourseTree.SelectedNode.Name))
                        {
                            string str3 = lesson2.GetFullURL();
                            if (File.Exists(str3))
                            {
                                this.ContentBrowser.Navigate(str3);
                            }
                        }
                    }
                }
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void ICMCourseForm_Load(object sender, EventArgs e)
        {
            this.LoadCourse();
        }

        private void InitializeComponent()
        {
            this.components = new Container();
            ComponentResourceManager manager = new ComponentResourceManager(typeof(ICMCourseForm));
            this.toolStrip = new ToolStrip();
            this.miNewCourse = new ToolStripButton();
            this.openCourse = new ToolStripButton();
            this.miTest = new ToolStripButton();
            this.toolStripSeparator1 = new ToolStripSeparator();
            this.miPrint = new ToolStripButton();
            this.toolStripSeparator3 = new ToolStripSeparator();
            this.miInfo = new ToolStripButton();
            this.toolStripSeparator2 = new ToolStripSeparator();
            this.miCheckResult = new ToolStripButton();
            this.toolStripSeparator4 = new ToolStripSeparator();
            this.miAddPositionUser = new ToolStripButton();
            this.toolStripButton1 = new ToolStripButton();
            this.toolStripButton1.Visible = false;

            this.splitContainer1 = new SplitContainer();
            this.CourseTree = new TreeView();
            this.imageList = new ImageList(this.components);
            this.ContentBrowser = new WebBrowser();
            this.toolStripButton2 = new ToolStripButton();
            this.toolStripButton2.Visible = false;

            this.info1 = new Info();
            this.toolStrip.SuspendLayout();
            this.splitContainer1.Panel1.SuspendLayout();
            this.splitContainer1.Panel2.SuspendLayout();
            this.splitContainer1.SuspendLayout();
            this.info1.BeginInit();
            base.SuspendLayout();
            this.toolStrip.ImageScalingSize = new Size(0x20, 0x20);
            this.toolStrip.Items.AddRange(new ToolStripItem[] { this.miNewCourse, this.openCourse, this.miTest, this.toolStripSeparator1, this.miPrint, this.toolStripSeparator3, this.miInfo, this.toolStripSeparator2, this.miCheckResult, this.toolStripSeparator4, this.miAddPositionUser, this.toolStripButton1, this.toolStripButton2 });
            this.toolStrip.Location = new Point(0, 0);
            this.toolStrip.Name = "toolStrip";
            this.toolStrip.Size = new Size(0x25d, 0x27);
            this.toolStrip.TabIndex = 0;
            this.toolStrip.Text = "toolStrip1";
            this.miNewCourse.DisplayStyle = ToolStripItemDisplayStyle.Image;
            this.miNewCourse.Image = (Image) manager.GetObject("miNewCourse.Image");
            this.miNewCourse.ImageTransparentColor = Color.Magenta;
            this.miNewCourse.Name = "miNewCourse";
            this.miNewCourse.Size = new Size(0x24, 0x24);
            this.miNewCourse.Text = "Добавить/изменить курс";
            this.miNewCourse.TextImageRelation = TextImageRelation.Overlay;
            this.miNewCourse.Visible = false;
            this.miNewCourse.Click += new EventHandler(this.miNewCourse_Click);
            this.openCourse.DisplayStyle = ToolStripItemDisplayStyle.Image;
            this.openCourse.Image = (Image) manager.GetObject("openCourse.Image");
            this.openCourse.ImageTransparentColor = Color.Magenta;
            this.openCourse.Name = "openCourse";
            this.openCourse.Size = new Size(0x24, 0x24);
            this.openCourse.Text = "Загрузить курс";
            this.openCourse.Click += new EventHandler(this.openCourse_Click);
            this.miTest.DisplayStyle = ToolStripItemDisplayStyle.Image;
            this.miTest.Image = (Image) manager.GetObject("miTest.Image");
            this.miTest.ImageTransparentColor = Color.Magenta;
            this.miTest.Name = "miTest";
            this.miTest.Size = new Size(0x24, 0x24);
            this.miTest.Text = "Тест";
            this.miTest.Click += new EventHandler(this.miTest_Click);
            this.toolStripSeparator1.Name = "toolStripSeparator1";
            this.toolStripSeparator1.Size = new Size(6, 0x27);
            this.miPrint.DisplayStyle = ToolStripItemDisplayStyle.Image;
            this.miPrint.Image = (Image) manager.GetObject("miPrint.Image");
            this.miPrint.ImageTransparentColor = Color.Magenta;
            this.miPrint.Name = "miPrint";
            this.miPrint.Size = new Size(0x24, 0x24);
            this.miPrint.Text = "Печать";
            this.miPrint.Click += new EventHandler(this.miPrint_Click);
            this.toolStripSeparator3.Name = "toolStripSeparator3";
            this.toolStripSeparator3.Size = new Size(6, 0x27);
            this.miInfo.DisplayStyle = ToolStripItemDisplayStyle.Image;
            this.miInfo.Image = (Image) manager.GetObject("miInfo.Image");
            this.miInfo.ImageTransparentColor = Color.Magenta;
            this.miInfo.Name = "miInfo";
            this.miInfo.Size = new Size(0x24, 0x24);
            this.miInfo.Text = "Информация";
            this.miInfo.Click += new EventHandler(this.miInfo_Click);
            this.toolStripSeparator2.Name = "toolStripSeparator2";
            this.toolStripSeparator2.Size = new Size(6, 0x27);
            this.miCheckResult.DisplayStyle = ToolStripItemDisplayStyle.Image;
            this.miCheckResult.Image = (Image) manager.GetObject("miCheckResult.Image");
            this.miCheckResult.ImageTransparentColor = Color.Magenta;
            this.miCheckResult.Name = "miCheckResult";
            this.miCheckResult.Size = new Size(0x24, 0x24);
            this.miCheckResult.Text = "Результаты";
            this.miCheckResult.Visible = false;
            this.miCheckResult.Click += new EventHandler(this.miCheckResult_Click);
            this.toolStripSeparator4.Name = "toolStripSeparator4";
            this.toolStripSeparator4.Size = new Size(6, 0x27);
            this.miAddPositionUser.DisplayStyle = ToolStripItemDisplayStyle.Image;
            this.miAddPositionUser.Image = (Image) manager.GetObject("miAddPositionUser.Image");
            this.miAddPositionUser.ImageTransparentColor = Color.Magenta;
            this.miAddPositionUser.Name = "miAddPositionUser";
            this.miAddPositionUser.Size = new Size(0x24, 0x24);
            this.miAddPositionUser.Text = "Регистрация";
            this.miAddPositionUser.Visible = false;
            this.miAddPositionUser.Click += new EventHandler(this.miAddPositionUser_Click);
            this.toolStripButton1.DisplayStyle = ToolStripItemDisplayStyle.Image;
            this.toolStripButton1.Image = (Image) manager.GetObject("toolStripButton1.Image");
            this.toolStripButton1.ImageTransparentColor = Color.Magenta;
            this.toolStripButton1.Name = "toolStripButton1";
            this.toolStripButton1.Size = new Size(0x24, 0x24);
            this.toolStripButton1.Text = "toolStripButton1";
            this.toolStripButton1.Click += new EventHandler(this.toolStripButton1_Click);
            this.splitContainer1.Dock = DockStyle.Fill;
            this.splitContainer1.Location = new Point(0, 0x27);
            this.splitContainer1.Name = "splitContainer1";
            this.splitContainer1.Panel1.AutoScroll = true;
            this.splitContainer1.Panel1.Controls.Add(this.CourseTree);
            this.splitContainer1.Panel1.RightToLeft = RightToLeft.No;
            this.splitContainer1.Panel1MinSize = 150;
            this.splitContainer1.Panel2.AutoScroll = true;
            this.splitContainer1.Panel2.Controls.Add(this.ContentBrowser);
            this.splitContainer1.Panel2.RightToLeft = RightToLeft.No;
            this.splitContainer1.Panel2MinSize = 100;
            this.splitContainer1.Size = new Size(0x25d, 0x162);
            this.splitContainer1.SplitterDistance = 150;
            this.splitContainer1.TabIndex = 1;
            this.CourseTree.Dock = DockStyle.Fill;
            this.CourseTree.Font = new Font("Tahoma", 11f, FontStyle.Regular, GraphicsUnit.Point, 0xcc);
            this.CourseTree.HideSelection = false;
            this.CourseTree.Location = new Point(0, 0);
            this.CourseTree.Name = "CourseTree";
            this.CourseTree.Size = new Size(150, 0x162);
            this.CourseTree.StateImageList = this.imageList;
            this.CourseTree.TabIndex = 0;
            this.CourseTree.AfterSelect += new TreeViewEventHandler(this.CourseTree_AfterSelect);
            this.imageList.ImageStream = (ImageListStreamer) manager.GetObject("imageList.ImageStream");
            this.imageList.TransparentColor = Color.Transparent;
            this.imageList.Images.SetKeyName(0, "1271872485_question-white.ico");
            this.imageList.Images.SetKeyName(1, "1271872889_address-book-open.ico");
            this.imageList.Images.SetKeyName(2, "1271873343_application-x-theme.ico");
            this.ContentBrowser.Dock = DockStyle.Fill;
            this.ContentBrowser.Location = new Point(0, 0);
            this.ContentBrowser.MinimumSize = new Size(400, 20);
            this.ContentBrowser.Name = "ContentBrowser";
            this.ContentBrowser.Size = new Size(0x1c3, 0x162);
            this.ContentBrowser.TabIndex = 0;
            this.toolStripButton2.DisplayStyle = ToolStripItemDisplayStyle.Image;
            this.toolStripButton2.Image = (Image) manager.GetObject("toolStripButton2.Image");
            this.toolStripButton2.ImageTransparentColor = Color.Magenta;
            this.toolStripButton2.Name = "toolStripButton2";
            this.toolStripButton2.Size = new Size(0x24, 0x24);
            this.toolStripButton2.Text = "toolStripButton2";
            this.toolStripButton2.Click += new EventHandler(this.toolStripButton2_Click);
            this.info1.DataSetName = "Info";
            this.info1.SchemaSerializationMode = SchemaSerializationMode.IncludeSchema;
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.ClientSize = new Size(0x25d, 0x189);
            base.Controls.Add(this.splitContainer1);
            base.Controls.Add(this.toolStrip);
            base.Name = "ICMCourseForm";
            this.Text = "Дистанционное обучение";
            base.WindowState = FormWindowState.Maximized;
            base.Load += new EventHandler(this.ICMCourseForm_Load);
            this.toolStrip.ResumeLayout(false);
            this.toolStrip.PerformLayout();
            this.splitContainer1.Panel1.ResumeLayout(false);
            this.splitContainer1.Panel2.ResumeLayout(false);
            this.splitContainer1.ResumeLayout(false);
            this.info1.EndInit();
            base.ResumeLayout(false);
            base.PerformLayout();
        }

        private void LoadCourse()
        {
            using (ICMOpenCourseForm form = new ICMOpenCourseForm())
            {
                if (form.ShowDialog() == DialogResult.OK)
                {
                    this.CourseDirectory = form.CourseDirectory;
                    this.CourseFileName = form.CourseFileName;
                    this.SetCourse(form.CourseFileName);
                    ICMTreeManager.RefreshViewTree(this.CourseTree, this._course);
                }
            }
        }

        private void LoadResToDataSet(ICMTestResult res)
        {
            DataRow row = this.ds.Tables["Company"].NewRow();
            if (this.ds.Tables["Company"].Rows.Count > 0)
            {
                foreach (DataRow row2 in this.ds.Tables["Company"].Rows)
                {
                    if (row2["Name"].ToString() == res.User.Company.ToString())
                    {
                        row = this.ds.Tables["Company"].Rows.Find(row2["ID"]);
                    }
                }
            }
            row["Name"] = res.User.Company;
            this.ds.Tables["Company"].Rows.Add(row);
            this.ds.Tables["Company"].AcceptChanges();
            DataRow row3 = this.ds.Tables["User"].NewRow();
            row3["Name"] = res.User.UserName;
            row3["Position"] = res.User.Position;
            row3["ID"] = row["ID"];
            this.ds.Tables["User"].Rows.Add(row3);
            this.ds.Tables["User"].AcceptChanges();
            foreach (ICMQuestion question in res.Course.Questions)
            {
                DataRow row4 = this.ds.Tables["Question"].NewRow();
                row4["Name"] = question.Text;
                this.ds.Tables["Question"].Rows.Add(row4);
                this.ds.Tables["Question"].AcceptChanges();
                foreach (ICMAnswer answer in question.Answers)
                {
                    DataRow row5 = this.ds.Tables["UserAnswers"].NewRow();
                    row5["Name"] = answer.Text;
                    row5["USER_ID"] = row3["ID"];
                    row5["QUESTION_ID"] = row4["ID"];
                    row5["IS_CHECKED"] = answer.UserChecked;
                    row5["IS_CORRECT"] = answer.IsCorrect;
                    this.ds.Tables["UserAnswers"].Rows.Add(row5);
                }
                this.ds.Tables["UserAnswers"].AcceptChanges();
            }
        }

        private void miAddPositionUser_Click(object sender, EventArgs e)
        {
            using (ICMRegData data = new ICMRegData())
            {
                data.ShowDialog();
            }
        }

        private void miCheckResult_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog dialog = new OpenFileDialog())
            {
                int num = 0;
                int num2 = 0;
                dialog.Filter = "Файлы результатов|*.dat";
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    using (FileStream stream = File.Open(dialog.FileName, FileMode.Open, FileAccess.Read))
                    {
                        BinaryFormatter formatter = new BinaryFormatter();
                        try
                        {
                            ICMTestResult result = (ICMTestResult) formatter.Deserialize(stream);
                            using (SaveFileDialog dialog2 = new SaveFileDialog())
                            {
                                dialog2.Filter = "html документы|*.html";
                                dialog2.AddExtension = true;
                                if (dialog2.ShowDialog() == DialogResult.OK)
                                {
                                    using (StreamWriter writer = File.CreateText(dialog2.FileName))
                                    {
                                        writer.WriteLine("<html>");
                                        writer.WriteLine("<body>");
                                        writer.WriteLine(string.Format("<p><b>{0}: {1}</b></p>", "ФИО", result.User.UserName));
                                        writer.WriteLine(string.Format("<p><b>{0}: {1}</b></p>", "Должность", result.User.Position));
                                        writer.WriteLine(string.Format("<p><b>{0}: {1}</b></p><br>", "Учреждение", result.User.Company));
                                        writer.WriteLine("<table border=\"1\">");
                                        writer.WriteLine("<tr>");
                                        writer.WriteLine(string.Format("<td>{0}</td>", "Вопрос:"));
                                        writer.WriteLine(string.Format("<td>{0}</td>", "Верные ответы:"));
                                        writer.WriteLine(string.Format("<td>{0}</td>", "Ответы пользователя:"));
                                        writer.WriteLine(string.Format("<td>{0}</td>", "Корректность ответа:"));
                                        writer.WriteLine("</tr>");
                                        if (result.Course.Questions.Count > 0)
                                        {
                                            foreach (ICMQuestion question in result.Course.Questions)
                                            {
                                                num2++;
                                                writer.WriteLine("<tr>");
                                                writer.WriteLine(string.Format("<td>{0}</td>", question.Text));
                                                string str = string.Empty;
                                                string str2 = string.Empty;
                                                string str3 = "+";
                                                foreach (ICMAnswer answer in question.Answers)
                                                {
                                                    str = str + (answer.IsCorrect ? (" - " + answer.Text) : string.Empty) + "<br>";
                                                    str2 = str2 + (answer.UserChecked ? (" - " + answer.Text) : string.Empty) + "<br>";
                                                    if (answer.UserChecked)
                                                    {
                                                        if (answer.IsCorrect)
                                                        {
                                                            num++;
                                                        }
                                                        else
                                                        {
                                                            str3 = "-";
                                                        }
                                                    }
                                                }
                                                // если ничего не выбрано 
                                                int answersCount = 0;
                                                foreach (ICMAnswer answer in question.Answers)
                                                {                                                    
                                                    if (answer.UserChecked)
                                                    {
                                                        answersCount++;
                                                    }
                                                }
                                                // если ничего не выбрано то это ошибка
                                                if (answersCount == 0)
                                                    str3 = "-";

                                                writer.WriteLine(string.Format("<td>{0}</td>", str.Trim("<br>".ToCharArray())));
                                                writer.WriteLine(string.Format("<td>{0}</td>", str2.Trim("<br>".ToCharArray())));
                                                writer.WriteLine(string.Format("<td>{0}</td>", str3.Trim("<br>".ToCharArray())));
                                                writer.WriteLine("</tr>");
                                            }
                                        }
                                        writer.WriteLine("</table><br>");
                                        writer.WriteLine(string.Format("<p>Итого: {0}/{1}</p>", num, num2));
                                        writer.WriteLine("</body>");
                                        writer.WriteLine("</html>");
                                        MessageBox.Show(string.Format("Результаты сохранены в {0}", dialog2.FileName));
                                    }
                                }
                            }
                        }
                        catch (Exception exception)
                        {
                            MessageBox.Show("Ошибка: \n" + exception.Message);
                        }
                    }
                }
            }
        }

        private void miInfo_Click(object sender, EventArgs e)
        {
            using (ICMAboutForm form = new ICMAboutForm())
            {
                form.ShowDialog();
            }
        }

        private void miNewCourse_Click(object sender, EventArgs e)
        {
            using (ICMEditorForm form = new ICMEditorForm())
            {
                form.ShowDialog();
            }
        }

        private void miPrint_Click(object sender, EventArgs e)
        {
            if (this.ContentBrowser.Document != null)
            {
                this.ContentBrowser.Document.ExecCommand("Print", true, 0);
            }
            else
            {
                MessageBox.Show("Для печати необходимо загрузить курс", "Печать", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
        }

        private void miTest_Click(object sender, EventArgs e)
        {
            if (this._course != null)
            {
                using (ICMTesterForm form = new ICMTesterForm())
                {
                    form.SetCourse(this._course);
                    form.ShowDialog();
                    return;
                }
            }
            MessageBox.Show("Для прохождения теста необходимо загрузить курс", "Пройти тест", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
        }

        private void openCourse_Click(object sender, EventArgs e)
        {
            this.LoadCourse();
        }

        private void SetCourse(string fileName)
        {
            if (!File.Exists(fileName))
            {
                throw new FileNotFoundException("Файл курса не найден", fileName);
            }
            BinaryFormatter formatter = new BinaryFormatter();
            using (FileStream stream = File.Open(fileName, FileMode.Open, FileAccess.Read))
            {
                this._course = (ICMCourse)formatter.Deserialize(stream);
                stream.Close();
            }
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            List<ICMTestResult> list = new List<ICMTestResult>();
            using (OpenFileDialog dialog = new OpenFileDialog())
            {
                dialog.Multiselect = true;
                dialog.Filter = "Файлы результатов|*.dat";
                if (DialogResult.OK == dialog.ShowDialog())
                {
                    foreach (string str in dialog.FileNames)
                    {
                        BinaryFormatter formatter = new BinaryFormatter();
                        using (FileStream stream = File.Open(str, FileMode.Open, FileAccess.Read, FileShare.Read))
                        {
                            ICMTestResult item = (ICMTestResult) formatter.Deserialize(stream);
                            list.Add(item);
                        }
                    }
                }
                using (SaveFileDialog dialog2 = new SaveFileDialog())
                {
                    dialog2.Filter = "HTML файлы|*.html";
                    dialog2.AddExtension = true;
                    if (DialogResult.OK == dialog2.ShowDialog())
                    {
                        using (StreamWriter writer = File.CreateText(dialog2.FileName))
                        {
                            writer.WriteLine("<html>");
                            writer.WriteLine("<body>");
                            writer.WriteLine("<table border=1>");
                            writer.WriteLine("<tr>");
                            writer.WriteLine(string.Format("<td>{0}</td>", "Учреждение"));
                            writer.WriteLine(string.Format("<td>{0}</td>", "ФИО"));
                            writer.WriteLine(string.Format("<td>{0}</td>", "Должность"));
                            writer.WriteLine(string.Format("<td>{0}</td>", "Итого"));
                            writer.WriteLine("</tr>");
                            foreach (ICMTestResult result2 in list)
                            {
                                writer.WriteLine("<tr>");
                                writer.WriteLine(string.Format("<td>{0}</td>", result2.User.Company));
                                writer.WriteLine(string.Format("<td>{0}</td>", result2.User.UserName));
                                writer.WriteLine(string.Format("<td>{0}</td>", result2.User.Position));
                                int num = 0;
                                int num2 = 0;
                                foreach (ICMQuestion question in result2.Course.Questions)
                                {
                                    num2++;
                                    foreach (ICMAnswer answer in question.Answers)
                                    {
                                        if (answer.IsCorrect && !answer.UserChecked)
                                        {
                                            num++;
                                            break;
                                        }
                                    }
                                }
                                writer.WriteLine(string.Format("<td>{0}/{1}</td>", num2 - num, num2));
                                writer.WriteLine("</tr>");
                            }
                            writer.WriteLine("</table>");
                            writer.WriteLine("</body>");
                            writer.WriteLine("</html>");
                            writer.Flush();
                            writer.Close();
                        }
                    }
                }
            }
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
        }

        public string CourseDirectory
        {
            get
            {
                return this._courseDirectory;
            }
            set
            {
                if (!Directory.Exists(value))
                {
                    throw new DirectoryNotFoundException("Указанная папка не существует");
                }
                this._courseDirectory = value;
            }
        }

        public string CourseFileName
        {
            get
            {
                return this._courseFileName;
            }
            set
            {
                if (!File.Exists(value))
                {
                    throw new FileNotFoundException("Указанный файл не существует", value);
                }
                this._courseFileName = value;
            }
        }
    }
}

